<template>
	<view class="user-roney">
		<block v-if="show">
			<view class="user-reply-tabs">
				<u-tabs
					:is-scroll="false"
					:list="replyTabs"
					active-color="#141414"
					:current="replyIndex"
					@change="change">
				</u-tabs>
			</view>
			<view class="consult-list" v-if="replyIndex == 0">
				<view class="consult-item" v-for="(item,index) in noAnswer" :key="index">
					<view class="item-head">
						<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/static/images/other/2021-04-14/20210414/83c1d5f8ccb885550e30e555ca160652.png" mode=""></image>
						<text>{{item.content}}</text>
					</view>
					<view class="item-goods" @click="goProInfo(item.goods_id)">
						<image :src="item.goods.image"></image>
						<view class="item-goods-info">
							<view class="item-goods-info-name">{{item.goods.goods_name}}</view>
							<view class="item-goods-info-date">原定时间：{{item.delivery_time}}</view>
						</view>
					</view>
					<view class="item-line"></view>
					<view class="item-bottom">
						<view class="item-bottom-sn">订单编号：{{item.order_sn}}</view>
						<view class="item-bottom-btn">
							
						</view>
					</view>
				</view>
				<pt-nothing
					text="您还没有提问"
					:fixed="true" 
					v-if="noMore && !noAnswer.length" 
					top="80" 
					icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
				</pt-nothing>
			</view>
			<pt-nomore v-if="noMore && noAnswer.length && replyIndex==0"></pt-nomore>
			<view class="consult-list" v-if="replyIndex == 1">
				<view class="consult-item" v-for="(item,index) in isAnswer" :key="index">
					<view class="item-head">
						<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/static/images/other/2021-04-14/20210414/83c1d5f8ccb885550e30e555ca160652.png" mode=""></image>
						<text>{{item.content}}</text>
					</view>
					<view class="item-head" v-for="(data,index2) in item.answer" :key="index2">
						<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/QA/A.png" mode=""></image>
						<text>{{data.content}}</text>
					</view>
					<view class="item-goods" @click="goProInfo(item.goods_id)">
						<image :src="item.goods.image"></image>
						<view class="item-goods-info">
							<view class="item-goods-info-name">{{item.goods.goods_name}}</view>
							<view class="item-goods-info-date" :style="{'marginTop': item.answer[0].plan_time?'8rpx':'20rpx'}">原定时间：{{item.delivery_time}}</view>
							<view class="item-goods-info-abnormal" v-if="item.answer[0].plan_time">延迟时间：{{item.answer[0].plan_time}}</view>
						</view>
					</view>
					<view class="item-line"></view>
					<view class="item-bottom">
						<view class="item-bottom-sn">订单编号：{{item.order_sn}}</view>
						<view class="item-bottom-btn">
							
						</view>
					</view>
				</view>
				<pt-nothing
					text="您还没有提问"
					:fixed="true"
					v-if="noMore1 && !isAnswer.length" 
					top="80"
					icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
				</pt-nothing>
			</view>
			<pt-nomore v-if="noMore1 && isAnswer.length && replyIndex==1"></pt-nomore>
			<pt-loading-more v-if="isLoading"></pt-loading-more>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				replyTabs: [{
					name: '未回答(0)'
				},{
					name: '已回答(0)'
				}],
				isLoading:false,
				replyIndex:0,
				page:0,
				page1:0,
				noMore:false,
				noMore1:false,
				noAnswer:[],//待回复
				isAnswer:[],//已回复
				Refresh:false,
				show:false
			}
		},
		onLoad(options) {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.replyIndex = options.replyIndex || 0
			this.init();
			// 设置当前链接，登录成功返回当前链接
			let pages = getCurrentPages();
			let curPage = pages[pages.length - 1];
			uni.setStorageSync('newurl',curPage.$page.fullPath)
		},
		methods: {
			// 切换
			change(e){
				this.replyIndex = e
				if(e == 0){
					this.noAnswer = []
					this.page = 0
					this.noMore = false
					this.getNoAnswer()
				}else if(e == 1){
					this.isAnswer = []
					this.page1 = 0
					this.noMore1 = false
					this.getAnswer()
				}
			},
			init(){
				this.getAnswer();
				this.getNoAnswer();
			},
			// 获取已回答列表
			getAnswer(){
				let data = {
					page: this.page1,
					get_goods: 1,
					is_answer: 1,
					user_id:this.userInfo.user_id
				}
				this.$u.apiWei.OrderGoodsAskLists(data).then(res=>{
					this.show = true
					this.isLoading = false
					if(res.counts){
						this.replyTabs[1].name = '已回答('+res.counts+')'
					}
					if(res.datas.length){
						res.datas.forEach(item => {
							this.isAnswer.push(item)
						})
					}else{
						this.noMore1 = true
					}
				})
			},
			// 获取待回答列表
			getNoAnswer(){
				let data = {
					page: this.page,
					get_goods: 1,
					is_answer: 0,
					user_id:this.userInfo.user_id
				}
				this.$u.apiWei.OrderGoodsAskLists(data).then(res=>{
					this.show = true
					this.isLoading = false
					if(res.counts){
						this.replyTabs[0].name = '未回答('+res.counts+')'
					}
					if(res.datas.length){
						res.datas.forEach(item => {
							this.noAnswer.push(item)
						})
					}else{
						this.noMore = true
					}
					if(this.Refresh){
						this.Refresh = false
						uni.stopPullDownRefresh({
							success: () => {
								uni.showToast({
									icon: 'none',
									title: '刷新成功'
								})
							}
						})
					}
				})
			},
			// 上啦加载更多
			onReachBottom() {
				if(this.QAindex==0){
					if(!this.noMore){
						this.page++
						this.isLoading = true
						this.getNoAnswer()
					}
				}else{
					if(!this.noMore1){
						this.page1++
						this.isLoading = true
						this.getAnswer()
					}
				}
			},
			onPullDownRefresh() {
				this.Refresh = true
				setTimeout(() => {
					this.show = false
					this.noAnswer = []
					this.isAnswer = []
					this.page = 0
					this.page1 = 0
					this.noMore = false
					this.noMore1 = false
					this.init()
				},500)
			},
			goProInfo(goods_id){
				getApp().goProInfo(goods_id)
			},
		}
	}
</script>

<style lang="scss">
.user-roney{
	.user-reply-tabs{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 99;
	}
	.consult-list{
		background-color: #f7f7f7;
		padding-top: 110rpx;
		min-height: 100vh;
		.consult-item{
			margin: 0 auto;
			margin-top: 30rpx;
			width: 690rpx;
			// height: 387rpx;
			padding: 30rpx 30rpx 24rpx 30rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 8rpx;
			&:first-child{
				margin-top: 0;
			}
			.item-head{
				display: flex;
				align-items: center;
				margin-bottom: 29rpx;
				image{
					display: block;
					width: 32rpx;
					height: 32rpx;
				}
				text{
					flex: 1;
					display: block;
					margin-left: 24rpx;
					font-size: 32rpx;
					color: #141414;
				}
			}
			.item-goods{
				display: flex;
				height: 160rpx;
				background-color: #f7f7f7;
				padding: 10rpx 10rpx 14rpx 10rpx;
				box-sizing: border-box;
				image{
					display: block;
					height: 136rpx;
					width: 136rpx;
				}
				.item-goods-info{
					margin-left: 33rpx;
					flex: 1;
					padding-right: 20rpx;
					.item-goods-info-name{
						width: 422rpx;
						height: 38rpx;
						margin-top: 10rpx;
						font-size: 28rpx;
						color: #444;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
					.item-goods-info-date{
						margin-top: 20rpx;
						font-size: 22rpx;
						color: #a4a4a4;
					}
					.item-goods-info-abnormal{
						margin-top: 8rpx;
						font-size: 22rpx;
						color:#F59359;
					}
				}
			}
			.item-line{
				margin-top: 36rpx;
				margin-bottom: 24rpx;
				width: 100%;
				height: 1rpx;
				background-color: #F7F7F7;
			}
			.item-bottom{
				display: flex;
				.item-bottom-sn{
					flex: 1;
					font-size: 22rpx;
					color: #909090;
					line-height: 52rpx;
				}
				.item-bottom-btn{
					display: flex;
				}
			}
		}
	}
}
</style>
